<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="layout" content="main" />
        <title>Project List</title>
    </head>
    <body>
        <div class="nav">
	
	<span class="menuButton"><g:link class="home" controller="person" action="home">Home</g:link></span>
	<g:if test="${!params.projectGroupId & session.user.role.name != 'Student'}"> 
        <span class="menuButton"><g:link class="create" action="create" params="[projectGroupId:params.projectGroupId]">New Project</g:link></span>
        </g:if>
	</div>
        <div class="body">
            <h1>${ProjectGroup.get(params.projectGroupId)}</h1>
            <g:if test="${flash.message}">
            <div class="message">${flash.message}</div>
            </g:if>
            <g:form method="post">
		<input type="hidden" name="projectGroupId" value="${params.projectGroupId}" />
            <div class="list">
                <table>
                    <thead>
                        <tr>
                       	
			<g:if test="${session.user.role.name == 'Organiser'}"> 
			<g:sortableColumn property="id" title="Id" />
      			</g:if> 
			
			<g:sortableColumn property="projectCode" title="Project Code" />
                        
               	        <g:sortableColumn property="supervisor" title="Supervisor" />
               	        <g:sortableColumn property="projectGroup" title="Project Group" />
                        
               	        <g:sortableColumn property="projectName" title="Project Name" width="150px" />

               	        <g:sortableColumn property="student" title="Student" />
				<g:if test="${(session.user.role.name == 'Organiser' & params.projectGroupId != null) | (params.projectGroupId == null & session.user.role.name != 'Student')}">
			<th>Report</th>	
			<th>Action</th>
			</g:if>
                        
                        </tr>
                    </thead>
                    
		    <tbody>
                    <g:each in="${projectList}" status="i" var="project">
                        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                        
			<g:if test="${session.user.role.name == 'Organiser'}"> 
			<td><g:link action="show" id="${project.id}">${fieldValue(bean:project, field:'id')}</g:link></td>
                        </g:if> 
			
			<td>${fieldValue(bean:project, field:'projectCode')}</td>
                        
                        <td>${fieldValue(bean:project, field:'supervisor')}</td>
                        <td>${fieldValue(bean:project, field:'group')}</td>
                        
			<g:if test="${!params.projectGroupId}">
			<td><g:link action="show" id="${project.id}">${fieldValue(bean:project, field:'projectName')}</g:link></td>
			</g:if>

                        <g:if test="${params.projectGroupId}">
			<td><g:link action="show" id="${project.id}" params="[projectGroupId:project.group.id]">${fieldValue(bean:project, field:'projectName')}</g:link></td>
 			</g:if>

			<td>
			<g:if test="${project.student}">
			<g:link action="show" controller="person" id="${project.student.id}">${project.student}</g:link>
			</g:if>
			<g:else>
			<g:if test="${session.user.role.name == 'Student'}"> 
			<g:radio name="projectChoice" value="${project.id}" />	
			</g:if>
			<g:else>
			None
			</g:else>
			</g:else>
			</td>
				<g:if test="${(session.user.role.name == 'Organiser' & params.projectGroupId != null) | (params.projectGroupId == null & session.user.role.name != 'Student')}">
			<td>
			<g:if test="${project.getReports().size() > 0}">
			<g:link action="list" controller="report" params='[projectId: "${project.id}"]'>View Report</g:link></td>
			</g:if>
			<g:else>
				N/A
			</g:else>
			</td>
			<td>
            <div class="buttons">
                <g:form>
                    <input type="hidden" name="id" value="${project?.id}" />
                     <span class="button"><g:actionSubmit class="edit" value="Edit" /></span>
                    <span class="button"><g:actionSubmit class="delete" onclick="return confirm('Are you sure?');" value="Delete" /></span>
                </g:form>
            </div>
			</td>
			</g:if> 
                        </tr>
                    </g:each>
                    </tbody>
                </table>
            </div>

		<g:if test="${session.user.role.name == 'Student'}">
                <div class="buttons">
			<span class="button"><g:actionSubmit class="save" value="Choose" action="Choose" /></span>
                </div>
		</g:if>
		
            <div class="paginateButtons">
                
		<input type="button" value="Back" onClick="history.back()">
		
            </div>
	</g:form>
        </div>
    </body>
</html>
